package com.example.lottoscratcho;

import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.TiledTextureRegion;
import org.andengine.ui.activity.BaseGameActivity;

import android.util.Log;

public class TimeBar {
	
//---------------------------------------------------------------------------FIELDS:
	
	private TiledTextureRegion mTextureRegion;
	private float xPos;
	private float yPos;
	private BaseGameActivity activity;
	public AnimatedSprite timebar;
	private float timeBarScale = 2.0f;
	
//--------------------------------------------------------------------------METHODS:
	
	TimeBar(TiledTextureRegion textReg, float xPos, float yPos, BaseGameActivity act) {
		
		this.mTextureRegion = textReg;
		this.xPos = xPos;
		this.yPos = yPos;
		this.activity = act;
		
		createTimeBar();
	}
	
	private void createTimeBar() {

		//Create new AnimateSprite
		this.timebar = new AnimatedSprite(xPos, yPos, 
								          mTextureRegion, 
								          activity.getVertexBufferObjectManager()) {
			
			@Override
			protected void onManagedUpdate(float pSecondsElapsed) {
				
				Log.d("TIME", String.valueOf(pSecondsElapsed));
				
				if (timeBarScale > 0) {
					
					timeBarScale -= 0.001;
					setScaleX(timeBarScale);
					
				}
				
				// Pass the seconds elapsed to our update thread
				super.onManagedUpdate(pSecondsElapsed);
			}
		
		};
		
		this.timebar.setScaleCenter(this.timebar.getWidth(), this.timebar.getHeight());
	}
	
	public void startTimeBar(long time) {
		
		this.timebar.animate(time);
		
	}
	
	public void stopTimeBar() {
		
		this.timebar.animate(0);
	}
	
		
}
